package com.xqls.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.xqls.biz.CostBiz;
import com.xqls.biz.DictionaryBiz;
import com.xqls.util.CommonPage;
import com.xqls.util.CommonResult;
import com.xqls.util.DictionaryEnums;
import com.xqls.util.GetKeyByValue;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@RequestMapping(value="/cost")
@Controller
public class CostController {
	
	@Autowired private CostBiz costBiz;
	
	@Autowired 
	private DictionaryBiz dictionaryBiz;
	
	@RequestMapping(value="/index")
	public ModelAndView index(){
		ModelAndView view = new ModelAndView("cost/costIndex");
		Map<Integer, String> map = dictionaryBiz.queryDictionaryByParent(DictionaryEnums.COMPANY_TYPE.getCode());
		view.addObject("deviceType", GetKeyByValue.getKey(map, "取水口"));
		return view;
	}
	
	@RequestMapping(value = "/costListData")
	@ResponseBody
	public CommonResult costListData(@RequestBody CommonPage commonPage, HttpServletRequest request, HttpServletResponse response){
		CommonResult result = costBiz.getCostByPage(commonPage,request,response);
		if(result.getIsSuccess()){
			result.setData(commonPage);
		}
		return result;
	}
	
	
}
